package com.labofjet.aspect;

import javax.persistence.EntityManager;

import com.labofjet.entity.Shadowable;
import com.labofjet.spring.common.SpringContextUtils;

public class ShadowAspect {

	//@PrePersist
	public void saveShadow(Object o) {
		EntityManager em = SpringContextUtils.getApplicationContext().getBean(EntityManager.class);
		Shadowable entity = (Shadowable) o;
		Object saved = entity.getShadowObject();
		em.persist(saved);
	}

	//@PreUpdate
	public void updateShadow(Object o) {
		EntityManager em = SpringContextUtils.getApplicationContext().getBean(EntityManager.class);
		Shadowable entity = (Shadowable) o;
		Object saved = entity.getShadowObject();
		em.merge(saved);
	}
}
